package cn.kgc.springboot03.controller;

import cn.kgc.springboot03.entity.Emp;
import cn.kgc.springboot03.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2022/12/27
 */
@Controller
@RequestMapping("emp")
public class EmpController {


    @Autowired
    private EmpService empService;

    @RequestMapping("list")
    @ResponseBody
    public List<Emp> getList(){
        List<Emp> emps = empService.empList();
        return emps;
    }

    @RequestMapping("list2")
    public String getEmpList(HttpSession session){
        List<Emp> emps = empService.empList();
        session.setAttribute("emps", emps);
        return "hello";
    }

    @RequestMapping("page")
    public String getEmpList(Integer page, Integer limit, Model model){
        List<Emp> emps = empService.getPage(page,limit);
        model.addAttribute("emps", emps);
        return "hello";
    }

}
